package com.imooc.ad.advice;

import com.imooc.ad.exception.AdException;
import com.imooc.ad.vo.CommonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/*
 * @author Qihs
 */

@RestControllerAdvice
//处理异常类 AdException
public class GlobalExceptionAdvice {

    //异常处理注解，如果不给值，默认处理所有异常
    @ExceptionHandler(value = AdException.class)
    public CommonResponse<String> handlerAdexception(HttpServletRequest req,
                                                     AdException ex){
        CommonResponse<String> response = new CommonResponse<>(-1, "business error");
        response.setData(ex.getMessage());
        return  response;
    }
}
